package com.example.book.controller;



import com.example.book.entity.Label;
import com.example.book.service.ILabelService;
import com.example.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 凡哥哥
 * @since 2023-11-07
 */
@RestController
@RequestMapping("/label")
@Slf4j
@Api(tags = "图书榜单控制器")
public class LabelController {
    @Autowired
    private ILabelService labelService;

    /**
     * 分页查询标签
     * @param page
     * @param pageSize
     * @param name
     * @return
     */
    @ApiOperation(value = "分页查询标签")
    @GetMapping("/page")
    public ResponseResult page(Integer page, Integer pageSize, String name){
        return labelService.pageInfo(page, pageSize, name);
    }
    /**
     * 添加榜单类型
     * @param label
     * @return
     */
    @ApiOperation(value = "添加榜单类型")
    @PostMapping
    public ResponseResult add(@RequestBody Label label){
        return labelService.addLabel(label);
    }

    /**
     * 数据回显
     * @param id
     * @return
     */
    @ApiOperation(value = "数据回显")
    @GetMapping("/{id}")
    public ResponseResult type(@PathVariable Integer id){
        return labelService.label(id);
    }

    /**
     * 修改方法
     * @param label
     * @return
     */
    @ApiOperation(value = "修改方法")
    @PutMapping
    public ResponseResult<String> update(@RequestBody Label label){
        log.info("修改图书类型信息:{}",label);
        labelService.updateById(label);
        return ResponseResult.okResult("修改图书类型成功");
    }

    /**
     * 修改状态
     *
     * @param
     * @return
     */
    @ApiOperation(value = "修改状态")
    @PutMapping("/status")
    public ResponseResult status(Long id) {
        return ResponseResult.okResult(labelService.updateStatus(id));
    }

    /**
     * 删除
     * @param ids
     * @return
     */
    @ApiOperation(value = "删除")
    @DeleteMapping
    public ResponseResult delete(Long [] ids) {
        return labelService.deleteLabel(ids);
    }
}

